//
// Created by zhuyijun on 2021/8/30.
//

#ifndef BASE_STUDENTC_H
#define BASE_STUDENTC_H

#include <iostream>
#include <string>
#include <valarray>

class Student {
private:
    //使用typedef 对std::valarray<double>进行简化表达
    typedef std::valarray<double> ArrayDb;
    std::string name;
    ArrayDb scores;
    std::ostream & arr_out(std::ostream & os) const;

public:
    Student() :name("Null Student"),scores() {}
    /**
     * C++中的explicit关键字只能用于修饰只有一个参数的类构造函数,
     * 它的作用是表明该构造函数是显示的, 而非隐式的,
     * 跟它相对应的另一个关键字是implicit, 意思是隐藏的,
     * 类构造函数默认情况下即声明为implicit(隐式)
     * @param s
     */
    explicit Student(const std::string & s):name(s),scores(){}
    explicit Student(int n):name("Nully"),scores(n){}
    Student(const std::string & s,  int n) :name(s),scores(n){}
    Student(const std::string & s,const ArrayDb & a):name(s),scores(a){}
    Student(const char * str,const double * pd,int n) :name(str),scores(pd,n){}
    ~Student(){}
    double Average() const;
    const std::string & Name() const;
    double & operator[](int i);
    double operator[](int i) const;

    //友元
    friend std::istream  & operator>>(std::istream & is,Student & stu);
    friend std::istream  & getline(std::istream & is,Student & stu);
    friend std::ostream & operator<<(std::ostream & os,const Student & stu);

};


#endif //BASE_STUDENTC_H
